<template>
  <PageWrapper contentFullHeight>
    <ListTemplate
      :register-table="registerTable"
      addauth="system:auxiliary:bar-code:add"
      :method="methods"
      :select-methods="selectMethods"
      :batch-del-btn="{ showbtn: true, auth: 'system:auxiliary:bar-code:batchdelete' }"
    />
    <Handle @register="registerLayer" @success="tableMethods.reload" />
    <BarCodeModel @register="registerModel" />
  </PageWrapper>
</template>
<script setup lang="ts">
  import ListTemplate from '@/views/common/operate/listTemplate.vue';

  import ApiV1 from '@/views/common/operate/ApiV1';
  import { createAsyncComponent } from '@/utils/factory/createAsyncComponent';

  import PageWrapper from '@/components/Page/src/PageWrapper.vue';
  import {
    useBarCodeListColumns,
    useBarCodeListSearchForm,
  } from '@/api/http/system/auxiliary/bar-code/bar-code.data';
  import {
    apiPostBarCodeDelete,
    apiPostBarCodeList,
  } from '@/api/http/system/auxiliary/bar-code/bar-code.api';
  import BarCodeModel from '@/views/system/auxiliary/barcode/barCodeModel.vue';
  import { useModal } from '@/components/Modal';
  import { toRaw } from 'vue';

  defineOptions({
    name: 'SystemBarCodeList',
  });
  const Handle = createAsyncComponent(() => import('./handle.vue'));
  const [registerModel, { openModal }] = useModal();
  const { registerTable, registerLayer, methods, tableMethods, selectMethods } = ApiV1.useList({
    tableProps: {
      api: apiPostBarCodeList,
      columns: useBarCodeListColumns(),
      formConfig: {
        schemas: useBarCodeListSearchForm(),
      },
      actionColumn: {
        width: 220,
      },
    },
    editActionItem: {
      auth: 'system:auxiliary:bar-code:edit',
    },
    delActionItem: {
      auth: 'system:auxiliary:bar-code:delete',
    },
    delFN: apiPostBarCodeDelete,
    queryParams: {
      delParam: async (record) => {
        return [record['id']];
      },
    },
    actionItems: (data, record) => {
      return [
        {
          label: '查看',
          icon: 'clarity:details-line',
          auth: 'system:auxiliary:bar-code:show',
          onClick: () => {
            openModal(true, toRaw(record));
          },
        },
      ];
    },
    auth: 'system:auxiliary:bar-code:list',
  });
</script>
